﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MxWeiXinPF.Common;

namespace MxWeiXinPF.Web
{
    public partial class login : Page
    {
        private MxWeiXinPF.BLL.wx_dt_user_BaseData daladd = new MxWeiXinPF.BLL.wx_dt_user_BaseData();
        private string popenid = "";
        private int pwid = 0x27;

        protected void btnReg_Click(object sender, EventArgs e)
        {
            base.Response.Redirect("register.aspx?ReturnURL=" + base.Request["ReturnURL"].ToString());
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            string str = this.txtUserName.Value.Trim();
            string password = this.txtPassWord.Value.ToString();
            if (string.IsNullOrEmpty(str))
            {
                this.msgtip.InnerHtml = "请输入用户名";
            }
            else if (string.IsNullOrEmpty(this.txtPassWord.Value.ToString()))
            {
                this.msgtip.InnerHtml = "请输入密码";
            }
            else
            {
                string str3 = "/shop/index.aspx?wid=39";
                string url = "";
                MxWeiXinPF.BLL.users users = new MxWeiXinPF.BLL.users();
                MxWeiXinPF.Model.users modelByOpenID = this.daladd.GetModelByOpenID(this.popenid);
                MxWeiXinPF.Model.users users3 = users.GetModel(str, password, 0, 0, false);
                if (users3 != null)
                {
                    if (modelByOpenID != null)
                    {
                        int num = this.daladd.UpdatePidAndShopid(users3.id.ToString(), modelByOpenID.id.ToString(), modelByOpenID.shopid);
                    }
                    this.Session["dt_session_user_info"] = users3;
                    this.Session.Timeout = 0x2d;
                    Utils.WriteCookie("DLUserName", users3.user_name);
                    Utils.WriteCookie("dt_cookie_user_name_remember", users3.user_name);
                    Utils.WriteCookie("dt_cookie_user_pwd_remember", users3.password);
                    if (base.Request["ReturnURL"] != null)
                    {
                        str3 = base.Request["ReturnURL"].ToString();
                    }
                    url = MyCommFun.urlAddOpenid(str3.Replace("openid", "popenid"), users3.wxOpenId);
                    HttpContext.Current.Response.Redirect(url);
                }
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                this.txtUserName.Value = Utils.GetCookie("DLUserName");
                if (base.Request["ReturnURL"] != null)
                {
                    string str = base.Request["ReturnURL"].ToString().Split(new char[] { '&' })[1];
                    this.popenid = str.Split(new char[] { '=' })[1];
                    string str2 = base.Request["ReturnURL"].ToString().Split(new char[] { '?' })[1].Split(new char[] { '&' })[0];
                    this.pwid = int.Parse(str2.Split(new char[] { '=' })[1]);
                }
            }
        }
    }
}